Graphics3D 800, 600, 32, 2


Const NUM_VALUES% = 5000000


Type SSE
	Field values0#[NUM_VALUES]
	Field values1#[NUM_VALUES]
	Field floatArray0#[NUM_VALUES]
	Field floatArray1#[NUM_VALUES]
End Type

Global sse.SSE = New SSE



; ===== Init =====
For i=0 To NUM_VALUES-1
	sse\values0[i] = Rand(1.0, 1000.0)
	sse\values1[i] = Rand(1.0, 1000.0)
	sse\floatArray0[i] = sse\values0[i]
	sse\floatArray1[i] = sse\values1[i]
Next



;----------------------------
;----- Test square root -----
;----------------------------

; === Classic ===
timeStart% = MilliSecs()
For i=0 To NUM_VALUES-1
	sse\values0[i] = Sqr(sse\values0[i])
Next
Print "sqrt classic : " + (MilliSecs() - timeStart) + " ms"

; === SSE ===
timeStart% = MilliSecs()
FloatArraySqrt(FieldArrayPointer(sse, 2), NUM_VALUES)
Print "sqrt SSE : " + (MilliSecs() - timeStart) + " ms"
Print

;-------------------------
;----- Test addition -----
;-------------------------

; === Classic ===
timeStart% = MilliSecs()
For i=0 To NUM_VALUES-1
	sse\values0[i] = sse\values0[i] + sse\values1[1]
Next
Print "add classic : " + (MilliSecs() - timeStart) + " ms"

; === SSE ===
timeStart% = MilliSecs()
FloatArrayAdd(FieldArrayPointer(sse, 2), FieldArrayPointer(sse, 3), NUM_VALUES)
Print "add SSE : " + (MilliSecs() - timeStart) + " ms"
Print

;----------------------------
;----- Test subtraction -----
;----------------------------

; === Classic ===
timeStart% = MilliSecs()
For i=0 To NUM_VALUES-1
	sse\values0[i] = sse\values0[i] - sse\values1[1]
Next
Print "sub classic : " + (MilliSecs() - timeStart) + " ms"

; === SSE ===
timeStart% = MilliSecs()
FloatArraySub(FieldArrayPointer(sse, 2), FieldArrayPointer(sse, 3), NUM_VALUES)
Print "sub SSE : " + (MilliSecs() - timeStart) + " ms"
Print

;-------------------------------
;----- Test multiplication -----
;-------------------------------

; === Classic ===
timeStart% = MilliSecs()
For i=0 To NUM_VALUES-1
	sse\values0[i] = sse\values0[i] * sse\values1[1]
Next
Print "mul classic : " + (MilliSecs() - timeStart) + " ms"

; === SSE ===
timeStart% = MilliSecs()
FloatArrayMul(FieldArrayPointer(sse, 2), FieldArrayPointer(sse, 3), NUM_VALUES)
Print "mul SSE : " + (MilliSecs() - timeStart) + " ms"
Print

;--------------------
;----- Test div -----
;--------------------

; === Classic ===
timeStart% = MilliSecs()
For i=0 To NUM_VALUES-1
	sse\values0[i] = sse\values0[i] / sse\values1[1]
Next
Print "div classic : " + (MilliSecs() - timeStart) + " ms"

; === SSE ===
timeStart% = MilliSecs()
FloatArrayDiv(FieldArrayPointer(sse, 2), FieldArrayPointer(sse, 3), NUM_VALUES)
Print "div SSE : " + (MilliSecs() - timeStart) + " ms"
Print

;--------------------
;----- Test min -----
;--------------------

; === Classic ===
timeStart% = MilliSecs()
For i=0 To NUM_VALUES-1
	If sse\values0[i] > sse\values1[1] Then sse\values0[i] = sse\values1[i]
Next
Print "min classic : " + (MilliSecs() - timeStart) + " ms"

; === SSE ===
timeStart% = MilliSecs()
FloatArrayMin(FieldArrayPointer(sse, 2), FieldArrayPointer(sse, 3), NUM_VALUES)
Print "min SSE : " + (MilliSecs() - timeStart) + " ms"
Print

;----------------------
;----- Test equal -----
;----------------------

; === Classic ===
timeStart% = MilliSecs()
For i=0 To NUM_VALUES-1
	If sse\values0[i] = sse\values1[1] Then sse\values0[i] = 1.0 : Else sse\values0[i] = 0.0
Next
Print "equal classic : " + (MilliSecs() - timeStart) + " ms"

; === SSE ===
timeStart% = MilliSecs()
FloatArrayEqual(FieldArrayPointer(sse, 2), FieldArrayPointer(sse, 3), NUM_VALUES)
Print "equal SSE : " + (MilliSecs() - timeStart) + " ms"
Print



WaitKey()
;~IDEal Editor Parameters:
;~C#Blitz3D